package top.leix.springdemo.controller;

import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import top.leix.springdemo.Res;
import top.leix.springdemo.annotation.AuthAccess;
import top.leix.springdemo.annotation.MyLog;
import top.leix.springdemo.pojo.*;
import top.leix.springdemo.services.AdministratorService;
import top.leix.springdemo.services.ApplyLabStudentService;
import top.leix.springdemo.services.ApplyLabTeacherService;

import javax.annotation.Resource;

@Slf4j
@Tag(name = "管理员接口")
@CrossOrigin
@RestController
@RequestMapping("/admin")
public class AdministratorController {
    @Resource
    AdministratorService administratorService;
    @Resource
    ApplyLabTeacherService applyLabTeacherService;
    @Resource
    ApplyLabStudentService applyLabStudentService;

    /**
     * 添加管理员接口,不打算做删除接口
     *
     * @param administrator me
     * @return
     */
    @PostMapping("/addAdministrator")
    public Res addAdministrator(@RequestBody Administrator administrator) {
        return administratorService.addAdministrator(administrator);
    }

    /**
     * 老师的控制流
     *
     * @return
     */
    @PostMapping("/queryAllTeacher")
    public Res queryAllTeacher() {
        return administratorService.queryAllTeacher();
    }

    //根据名字查
    @PostMapping("/queryTeacherByName")
    public Res queryTeacherByName(@RequestBody String userName) {
        return administratorService.queryTeacherByName(userName);
    }

    @PostMapping("/addTeacher")
    public Res addTeacher(@RequestBody Teacher teacher) {
        return administratorService.addTeacher(teacher);
    }

    @PostMapping("/updateTeacher")
    public Res updateTeacher(@RequestBody Teacher teacher) {

        return administratorService.updateTeacher(teacher);
    }

    @PostMapping("deleteTeacherByAccount")
    public Res deleteTeacherByAccount(@RequestBody String userAccount) {
        return administratorService.deleteTeacher(userAccount);
    }

    /**
     * 学生的控制流
     *
     * @return
     */
    @MyLog
    @AuthAccess //自定义权限注解，打上这个注解可以跳过Token验证，因为拦截器那边的逻辑就是打上就跳过
    @PostMapping("/queryAllStudent")
    public Res queryAllStudent() {
        return administratorService.queryAllStudent();
    }

    //根据名字查
    @PostMapping("/queryStudentByName")
    public Res queryStudentByName(@RequestBody String userName) {
        return administratorService.queryStudentByName(userName);
    }

    @PostMapping("/addStudent")
    public Res addStudent(@RequestBody Student student) {
        return administratorService.addStudent(student);
    }

    @PostMapping("/updateStudent")
    public Res updateStudent(@RequestBody Student student) {
        return administratorService.updateStudent(student);
    }

    @PostMapping("deleteStudentByAccount")
    public Res deleteStudentByAccount(@RequestBody String userAccount) {
        return administratorService.deleteStudent(userAccount);
    }

    /**
     * 实验员的控制流
     *
     * @return
     */
    @PostMapping("/queryAllLabAssistant")
    public Res queryAllLabAssistant() {
        return administratorService.queryAllLabAssistant();
    }

    //根据名字查
    @PostMapping("/queryLabAssistantByName")
    public Res queryLabAssistantByName(@RequestBody String userName) {
        return administratorService.queryLabAssistantByName(userName);
    }

    @PostMapping("/addLabAssistant")
    public Res addLabAssistant(@RequestBody LabAssistant LabAssistant) {
        return administratorService.addLabAssistant(LabAssistant);
    }

    @PostMapping("/updateLabAssistant")
    public Res updateLabAssistant(@RequestBody LabAssistant LabAssistant) {
        return administratorService.updateLabAssistant(LabAssistant);
    }

    @PostMapping("deleteLabAssistantByAccount")
    public Res deleteLabAssistantByAccount(@RequestBody String userAccount) {
        return administratorService.deleteLabAssistant(userAccount);
    }

    /**
     * Terms的控制流
     *
     * @return
     */

    //查询所有学期
    @PostMapping("/queryAllTerm")
    public Res queryAllTerm() {
        return administratorService.queryAllTerm();
    }

    //查询当前学期
    @PostMapping("/queryNowTerm")
    public Res queryNowTerm() {
        return administratorService.queryNowTerm();
    }

    //添加学期,isNow默认属性是0
    @MyLog
    @PostMapping("/addTerm")
    public Res addTerm(@RequestBody Terms terms) {
        return administratorService.addTerm(terms);
    }

    //修改学期
    @PostMapping("/updateTerm")
    public Res updateTerm(@RequestBody Terms terms) {
        return administratorService.updateTerm(terms);
    }

    //设置当前学期，isNow只能有一个是1，其他都是0
    @PostMapping("/setNowTerm")
    public Res setNowTerm(@RequestBody Terms terms) {
        return administratorService.setNowTerm(terms);
    }

    //根据学期删除
    @PostMapping("deleteSemester")
    public Res deleteSemester(@RequestBody String semester) {
        return administratorService.deleteSemester(semester);
    }

    /**
     * 表单的控制流
     */

    /**
     * 查看老师提交的所有表单
     */
    @PostMapping("queryAllTeacherApply")
    public Res queryAllTeacherApply() {
        return applyLabTeacherService.queryAllTeacherApply();
    }
    /**
     * 查看老师提交的未审核表单
     */
    @PostMapping("queryToCheckTeacher")
    public Res toCheckTeacher() {
        return applyLabTeacherService.queryToCheckTeacher();
    }
    /**
     * 更改教师的提交表单的状态
     */
    @PostMapping("updateTeacherApplyStatus")
    public Res updateTeacherApplyStatus( Integer applyID, String status) {
        return applyLabTeacherService.updateApplicationStatus(applyID, status);
    }

    /**
     * 查看所有学生的表单
     */
    @MyLog
    @PostMapping("queryAllStudentApply")
    public Res queryAllStudentApply() {
        return applyLabStudentService.queryAllStudentApply();
    }
    
    /**
     * 查看学生提交的未审核表单
     */
    @PostMapping("queryToCheckStudent")
    public Res toCheckStudent() {
        return applyLabStudentService.queryToCheckStudent();
    }
    /**
     * 更改学生的提交表单的状态，传过来的是OK或者Rejection
     */
    @PostMapping("updateStudentApplyStatus")
    public Res updateStudentApplyStatus( Integer applyID, String status) {
        return applyLabStudentService.updateApplicationStatus(applyID, status);
    }

    /**
     * 修改老师的申请状态为拒绝
     */
    @PostMapping("updateTeacherApplyRejection")
    public Res updateTeacherApplyRejection( Integer applyID) {
        return applyLabTeacherService.updateTeacherApplyRejection(applyID);
    }


    /**
     * 提交排课表
     */
    @PostMapping("addClasstable")
    public Res addClasstable(@RequestBody Classtable classtable) {
        return administratorService.addClasstable(classtable);
    }


}
